<template>
  <div class="app-container">
    <div class="line"></div>
    <header v-if="product_list.length">
      <p class="title">Endless games Endless fun</p>
    </header>
    <main>
      <div class="game-wrap">
        <swiper :options="swiperOption" class="swiper_banner _flex">
          <swiper-slide
            v-for="(item, index) in product_list"
            :key="index"
            class="game"
          >
            <div class="image">
              <img v-lazy="item.images[0]" alt="" @click="toGameItem(item)" />
            </div>
            <p class="name">{{ item.name }}</p>
            <p @click="toGameItem(item)" class="text">GET INTO</p>
          </swiper-slide>
        </swiper>
      </div>
    </main>
  </div>
</template>

<script setup>
import { productList } from "@/api/product";
import { useRoute, useRouter } from "vue-router";
import { ref } from "vue";

const route = useRoute();
const router = useRouter();

// 轮播参数
const swiperOption = ref({
  observer: true,
  observeParents: true,
  observeSlideChildren: true,
  autoplay: {
    delay: 3000,
    stopOnLastSlide: false,
    disableOnInteraction: true,
  },
  slidesPerView: 5,
  loop: true,
  loopPreventsSlide: false,
  loopedSlides: 5,
});

// 获取游戏列表
const product_list = ref([]);
const getProductList = () => {
  productList({
    category_id: [100293],
    page: 1,
    per_page: 19,
  }).then((res) => {
    product_list.value = res.data.data;
    // console.log(product_list.value);
  });
};
getProductList();

// 跳转游戏详情
const toGameItem = (item) => {
  router.push({
    path: "/gameItem",
    query: { id: item.id },
  });
};
</script>

<style lang="scss" scoped>
.app-container {
  margin-top: 60px;
  .line {
    width: 2px;
    height: 50px;
    background: #ffa300;
    margin: 0 auto;
    margin-bottom: 40px;
    margin-top: 40px;
  }
  header {
    margin-bottom: 40px;
    height: 130px;
    display: flex;
    justify-content: center;
    align-items: center;
    .title {
      font-size: 60px;
      text-align: center;
      color: #bdbcbf;
    }
  }
  main {

    height: fit-content;
    // 轮播列表
    .swiper-container {
      // height: 500px !important;
      // 轮播列表
      .swiper-slide {
        width: 300px;
        height: 300px;
        box-sizing: border-box;
      }
    }
    .game {
      .image {
        width: 100%;
        height: 60%;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
          transition: transform 0.5s ease;
          cursor: pointer;
          &:hover {
            transform: scale(1.1);
          }
        }
      }
      p {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        // font-weight: 700;
        background: #1f2635;
        color: #8d8d8d;
        border-right: 1px solid #464545;
      }
      .name {
        height: 20%;
        color:#ffa300;
        font-size: 18px;
        text-align: center;
      }
      .text {
        height: 20%;
        border-top: 1px solid #464545;
        cursor: pointer;
        &:hover {
          color: #ffa300;
        }
      }
    }
  }
}
</style>
